"""
=================================
Gaussian Mixture Model Ellipsoids
=================================

"""
# https://scikit-learn.org/dev/auto_examples/mixture/plot_gmm.html#sphx-glr-auto-examples-mixture-plot-gmm-py

import itertools

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

from sklearn import mixture

color_iter = itertools.cycle(['navy', 'c', 'cornflowerblue', 'gold', 'darkorange'])


def plot_results(X, Y_, means, covariances, title, pltdimen1, pltdimen2):
    for i, (mean, covar, color) in enumerate(zip(
            means, covariances, color_iter)):
        # 由于DP不会使用它所访问的每一个组件，除非它需要它，所以我们不应该绘制冗余组件。
        if not np.any(Y_ == i):
            continue
        plt.scatter(X[Y_ == i, pltdimen1],
                    X[Y_ == i, pltdimen2],
                    .8, color=color)

    # plt.xlim(-1, 20)
    # plt.ylim(-1, 20)
    # plt.xticks(())
    # plt.yticks(())
    plt.title(title)


market = "hair_dryer"
# market = "microwave"
# market = "pacifier"

tttt = pd.read_excel("./2c_output/successful_failing_product_2c_" + market + '.xlsx', 'Sheet1')
print(tttt.head())
X = tttt.values[:, 1:7]
# print(X[1:5, 1:7])
# print(X[1:5])


'''
该product_id的所有评论 的 平均star_rating
该product_id的所有评论 的 数量
该product_id所有的review_headline和review_body的长度之和
该product_id所有的review_headline和review_body的好词个数
该product_id所有的review_headline和review_body的坏词个数
'''


# 绘制好词坏词
pltdimen1 = 3
pltdimen2 = 4

# Fit a Gaussian mixture with EM using five components
gmm = mixture.GaussianMixture(n_components=5, covariance_type='full').fit(X)
plt.figure()
plot_results(X, gmm.predict(X), gmm.means_, gmm.covariances_,
             'Gaussian Mixture', pltdimen1, pltdimen2)

# # Fit a Dirichlet process Gaussian mixture using five components
# dpgmm = mixture.BayesianGaussianMixture(n_components=5, covariance_type='full').fit(X)
# plt.figure()
# plot_results(X, dpgmm.predict(X), dpgmm.means_, dpgmm.covariances_,
#              'Bayesian Gaussian Mixture with a Dirichlet process prior', pltdimen1, pltdimen2)

plt.show()
